package cn.edu.scau.cmi.linjinyong.mybatis.dao.impl;

import cn.edu.scau.cmi.linjinyong.mybatis.dao.TeacherDao;
import cn.edu.scau.cmi.linjinyong.mybatis.domain.Teacher;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.List;

public class TeacherDaoImpl implements TeacherDao {
    private SqlSessionTemplate sqlSession;
    @Override
    public List<Teacher> listTeachers() {
        return sqlSession.selectList("cn.edu.scau.cmi.linjinyong.mybatis.dao.TeacherDao.listTeachers");
    }

    @Override
    public boolean deleteTeacher(long id) {
        return sqlSession.delete("cn.edu.scau.cmi.linjinyong.mybatis.dao.TeacherDao.deleteTeacher", id)>0;
    }

    @Override
    public boolean updateTeacher(Teacher teacher) {
        return sqlSession.update("cn.edu.scau.cmi.linjinyong.mybatis.dao.TeacherDao.updateTeacher", teacher)>0;
    }

    @Override
    public boolean addTeacher(Teacher teacher) {
        return sqlSession.insert("cn.edu.scau.cmi.linjinyong.mybatis.dao.TeacherDao.addTeacher", teacher)>0;
    }

    public SqlSessionTemplate getSqlSession() {
        return sqlSession;
    }

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }
}
